#include <string>
#include <iostream>

#include "toolchain/slog.h"
#include "toolchain/plog.h"

#include <gtest/gtest.h>
#include <gmock/gmock.h>

#ifndef private
#define private public
#include "acl/acl.h"
#include "acl/acl_mdl.h"
#include "log_inner.h"
#include "json_parser.h"
#include "toolchain/dump.h"
#include "toolchain/profiling.h"
#include "toolchain/profiling_manager.h"
#include "toolchain/prof_api.h"
#include "acl/acl_prof.h"
#include "common/common_inner.h"
#include "executor/ge_executor.h"
#include "acl_stub.h"
#undef private
#endif

using namespace testing;
using namespace std;
using namespace acl;
using namespace ge;
using testing::Return;

std::vector<uint32_t> profTypeCnt;

class UTEST_ACL_toolchain : public testing::Test
{
    public:
        UTEST_ACL_toolchain(){}
    protected:
        virtual void SetUp() {}
        virtual void TearDown() {
            Mock::VerifyAndClear((void *)(&MockFunctionTest::aclStubInstance()));
        }
};

INT32 mmGetEnvStub(const CHAR *name, CHAR *value, UINT32 len)
{
    char environment[MMPA_MAX_PATH] = "";
    (void)memcpy_s(value, MMPA_MAX_PATH, environment, MMPA_MAX_PATH);
    return 0;
}

static int32_t MsprofReportDataStub(uint32_t moduleId, uint32_t type, void *data, uint32_t len)
{
   return 0;
}

static int32_t MsprofRegTypeInfoStub(uint16_t level, uint32_t typeId, const char *typeName)
{
    return 2;
}

static int32_t MsprofRegTypeInfoStub2(uint16_t level, uint32_t typeId, const char *typeName)
{
    if ((typeId > MSPROF_REPORT_ACL_OP_BASE_TYPE) && (typeId < MSPROF_REPORT_ACL_MODEL_BASE_TYPE)) {
        return 2;
    }
    return 0;
}

static int32_t MsprofRegTypeInfoStub3(uint16_t level, uint32_t typeId, const char *typeName)
{
    if ((typeId > MSPROF_REPORT_ACL_MODEL_BASE_TYPE) && (typeId < MSPROF_REPORT_ACL_RUNTIME_BASE_TYPE)) {
        return 2;
    }
    return 0;
}

static int32_t MsprofRegTypeInfoStubForCnt(uint16_t level, uint32_t typeId, const char *typeName)
{
    profTypeCnt.emplace_back(typeId);
    return 0;
}

TEST_F(UTEST_ACL_toolchain, dumpApiNotSupportTest)
{
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = true;
    aclError ret = aclmdlInitDump();
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump("llt/acl/ut/json/dumpConfig.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlFinalizeDump();
    EXPECT_NE(ret, ACL_SUCCESS);
}

static int AdxDataDumpServerInitInvoke()
{
    int initRet = 1;
    return initRet;
}

TEST_F(UTEST_ACL_toolchain, dumpInitFailed)
{
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = true;
    acl::AclDump::GetInstance().SetAclDumpFromAclInitFlag(false);
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), AdxDataDumpServerInit())
        .WillRepeatedly(Invoke(AdxDataDumpServerInitInvoke));
    aclError ret = aclmdlInitDump();
    EXPECT_EQ(ret, ACL_ERROR_INTERNAL_ERROR);
}

TEST_F(UTEST_ACL_toolchain, dumpParamTest)
{
    acl::AclDump aclDump;
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    aclError ret = aclmdlInitDump();
    EXPECT_EQ(ret, ACL_SUCCESS);

    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump1.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump2.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump3.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump4.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_list field illegal
    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testDump5.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testDump6.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    // invalid dump_op_switch
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump7.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // invalid dumppathIp
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump8.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // model name is empty
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump9.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    // dump_op_switch field is not exist
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump10.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    // dump_op_switch field is off,dump_list is empty
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump11.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    // dump_op_switch field is illegal
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump12.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_mode field is illegal
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump13.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_path is empty
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump14.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // no dump item
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump15.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_list field is illegal
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump16.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump17.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // ip is invalid
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump18.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of reverse range
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump19.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump20.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump21.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump22.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump23.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump24.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump25.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump26.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    // dump_step field is illegal cuz of wrong format
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump27.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump28.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher1.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher2.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher3.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher4.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher5.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher6.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher7.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher8.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher9.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher10.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpWatcher11.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpDataCheck.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpLevelOp.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpLevelKernel.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpLevelInvalid.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpStatsCheck1.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpStatsCheck2.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_op_switch is on in dump overflow detection
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump1.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_path is invalid in dump overflow detection
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump2.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_list is valid  in dump overflow detection
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump3.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_list is invalid/dump_op_switch is "off"/dump_path is valid in dump overflow detection
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump4.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_list is empty/dump_op_switch is "off"/dump_path is valid in dump overflow detection
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump5.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    //dump_op_switch is not in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump6.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //dump_path is not in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump7.json");
    EXPECT_NE(ret, ACL_SUCCESS);

    //only dump_path and dump_debug in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump8.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    //only dump_path and dump_op_switch in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump9.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    //only dump_path and dump_list in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump11.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    //only dump_path in dump info
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDebugDump10.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    //simple lite_exception_with_shape config
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testLiteExceptionDump_with_shape.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpOff1.json");
    EXPECT_EQ(ret, ACL_SUCCESS);
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), mmAccess2(_,_))
            .WillOnce(Return(-1))
            .WillRepeatedly(Return(0));
    ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/testDumpOff1.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    // aclInit dump
    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/dumpConfig.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpLevelOp.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testDump_DumpLevelKernel.json");
    EXPECT_EQ(ret, ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, dumpNotInitTest)
{
    acl::AclDump::GetInstance().SetAclDumpFromAclInitFlag(false);
    aclmdlFinalizeDump();
    aclError ret = aclmdlSetDump("llt/acl/ut/json/dumpConfig.json");
    EXPECT_NE(ret, ACL_SUCCESS);
    EXPECT_NE(aclmdlFinalizeDump(), ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, repeatExecuteAclmdlInitDumpTest)
{
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    aclError ret = aclmdlInitDump();
    EXPECT_EQ(ret, ACL_SUCCESS);
    EXPECT_NE(aclmdlInitDump(), ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, SetDumpConfigFailedTest)
{
    aclInit(nullptr);
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), SetDump(_))
        .WillOnce(Return((FAILED)));

    aclError ret = aclmdlSetDump(ACL_BASE_DIR "/tests/ut/acl/json/dumpConfig.json");
    EXPECT_NE(ret, ACL_SUCCESS);
}


TEST_F(UTEST_ACL_toolchain, dumpFinalizeFailedTest)
{
    acl::AclDump::GetInstance().SetAclDumpFromAclInitFlag(false);
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    // Clear dump config failed in aclmdlFinalizeDump
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), SetDump(_))
        .WillOnce(Return((FAILED)));
    aclError ret = aclmdlFinalizeDump();
    EXPECT_NE(ret, ACL_SUCCESS);
    Mock::VerifyAndClear((void *)(&MockFunctionTest::aclStubInstance()));

    // kill dump server failed
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), AdxDataDumpServerUnInit())
        .WillOnce(Return(1));
    ret = aclmdlFinalizeDump();
    EXPECT_EQ(ret, ACL_ERROR_INTERNAL_ERROR);
}

TEST_F(UTEST_ACL_toolchain, LiteExceptionDumpTest)
{
    acl::AclDump aclDump;
    acl::AclDump::GetInstance().aclDumpFromAclInitFlag_ = false;
    auto ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteExceptionDump.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteException_debug_off.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteExceptionDump_with_shape.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    // dump_scene field illegal
    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteException_empty.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteException_unspport.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteException_debug_on.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);

    ret = aclDump.HandleDumpConfig(ACL_BASE_DIR "/tests/ut/acl/json/testLiteException_op_on.json");
    EXPECT_EQ(ret, ACL_ERROR_INVALID_DUMP_CONFIG);
}
// ========================== profiling testcase =============================

TEST_F(UTEST_ACL_toolchain, setDeviceSuccess)
{
    acl::AclProfilingManager aclProfManager;
    uint32_t deviceIdList[] = {1, 2, 3};
    aclError ret = aclProfManager.AddDeviceList(nullptr, 0);
    EXPECT_EQ(ret, ACL_SUCCESS);
    ret = aclProfManager.AddDeviceList(deviceIdList, 3);
    EXPECT_EQ(ret, ACL_SUCCESS);
    ret = aclProfManager.RemoveDeviceList(nullptr, 0);
    EXPECT_EQ(ret, ACL_SUCCESS);
    ret = aclProfManager.RemoveDeviceList(deviceIdList, 3);
    EXPECT_EQ(ret, ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingManagerInitFailed)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
    .WillOnce(Return(2));
    acl::AclProfilingManager aclProfManager;
    aclError ret = aclProfManager.Init();
    EXPECT_NE(ret, ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingManagerUnInitFailed)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
    .WillOnce(Return(2));
    acl::AclProfilingManager aclProfManager;
    aclError ret = aclProfManager.UnInit();
    EXPECT_NE(ret, ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, HandleProfilingConfig)
{
    acl::AclProfiling aclProf;
    aclError ret = aclProf.HandleProfilingConfig(nullptr);
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclProf.HandleProfilingConfig(ACL_BASE_DIR "/tests/ut/acl/json/profConfig.json");
    EXPECT_EQ(ret, ACL_SUCCESS);

    ret = aclProf.HandleProfilingConfig(ACL_BASE_DIR "/tests/ut/acl/json/profilingConfig.json");
    EXPECT_EQ(ret, ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, HandleProfilingCommand)
{
    acl::AclProfiling aclprof;
    const string config = "test";
    bool configFileFlag = false;
    bool noValidConfig = false;
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofInit(_,_,_))
        .WillRepeatedly(Return(1));
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofInit(_,_,_))
    .WillRepeatedly(Return(1));
    aclError ret = aclprof.HandleProfilingCommand(config, configFileFlag, noValidConfig);
    EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);

    configFileFlag = true;
    noValidConfig = false;
    ret = aclprof.HandleProfilingCommand(config, configFileFlag, noValidConfig);
    EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
}

int32_t MsprofReporterCallbackImpl(uint32_t moduleId, uint32_t type, void *data, uint32_t len)
{
    return 0;
}

TEST_F(UTEST_ACL_toolchain, MsprofCtrlHandle)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
    .WillOnce(Return(2));
    rtProfCommandHandle_t command;
    command.profSwitch = 1;
    command.devNums = 1;
    command.devIdList[0] = 0;
    command.type = 1;
    auto ret = AclProfCtrlHandle(RT_PROF_CTRL_SWITCH, static_cast<void *>(&command), sizeof(rtProfCommandHandle_t));
    EXPECT_NE(ret, ACL_SUCCESS);

    ret = AclProfCtrlHandle(RT_PROF_CTRL_SWITCH, static_cast<void *>(&command), sizeof(rtProfCommandHandle_t) - 1);
    EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter)
{
    AclProfilingManager::GetInstance().isProfiling_ = true;
    AclProfilingManager::GetInstance().deviceList_.insert(-1);
    AclProfilingManager::GetInstance().deviceList_.insert(0);
    AclProfilingReporter reporter(acl::AclProfType::AclmdlSetDynamicHWSize);
    EXPECT_EQ(reporter.aclApi_, acl::AclProfType::AclmdlSetDynamicHWSize);
    reporter.~AclProfilingReporter();
    AclProfilingReporter reporter1(acl::AclProfType::AclMallocMemInner);
    EXPECT_EQ(reporter1.aclApi_, acl::AclProfType::AclMallocMemInner);
    reporter1.~AclProfilingReporter();
    AclProfilingManager::GetInstance().isProfiling_ = false;
    AclProfilingManager::GetInstance().deviceList_.erase(-1);
    AclProfilingManager::GetInstance().deviceList_.erase(0);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_2)
{
    AclProfilingManager::GetInstance().isProfiling_ = true;
    AclProfilingManager::GetInstance().deviceList_.insert(-1);
    AclProfilingManager::GetInstance().deviceList_.insert(0);
    AclProfilingReporter reporter(acl::AclProfType::AclmdlSetDynamicHWSize);
    EXPECT_EQ(reporter.aclApi_, acl::AclProfType::AclmdlSetDynamicHWSize);
    reporter.~AclProfilingReporter();
    AclProfilingManager::GetInstance().isProfiling_ = false;
    AclProfilingManager::GetInstance().deviceList_.erase(-1);
    AclProfilingManager::GetInstance().deviceList_.erase(0);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_3)
{
    AclProfilingManager::GetInstance().isProfiling_ = true;
    AclProfilingManager::GetInstance().deviceList_.insert(-1);
    AclProfilingManager::GetInstance().deviceList_.insert(0);
    AclProfilingReporter reporter(acl::AclProfType::AclmdlSetDynamicHWSize);
    EXPECT_EQ(reporter.aclApi_, acl::AclProfType::AclmdlSetDynamicHWSize);
    reporter.~AclProfilingReporter();
    AclProfilingManager::GetInstance().isProfiling_ = false;
    AclProfilingManager::GetInstance().deviceList_.erase(-1);
    AclProfilingManager::GetInstance().deviceList_.erase(0);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_4)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
    .WillOnce(Invoke(MsprofReportDataStub));
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofRegTypeInfo(_,_,_))
    .WillRepeatedly(Return(0));
    EXPECT_EQ(AclProfilingManager::GetInstance().Init(), ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_5)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
    .WillOnce(Invoke(MsprofReportDataStub));
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofRegTypeInfo(_,_,_))
    .WillRepeatedly(Invoke(MsprofRegTypeInfoStub));
    EXPECT_NE(AclProfilingManager::GetInstance().Init(), ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_6)
{
EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
.WillOnce(Invoke(MsprofReportDataStub));
EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofRegTypeInfo(_,_,_))
.WillRepeatedly(Invoke(MsprofRegTypeInfoStub2));
EXPECT_NE(AclProfilingManager::GetInstance().Init(), ACL_SUCCESS);
}

TEST_F(UTEST_ACL_toolchain, AclProfilingReporter_7)
{
EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofReportData(_,_,_,_))
.WillOnce(Invoke(MsprofReportDataStub));
EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofRegTypeInfo(_,_,_))
.WillRepeatedly(Invoke(MsprofRegTypeInfoStub3));
EXPECT_NE(AclProfilingManager::GetInstance().Init(), ACL_SUCCESS);
}


TEST_F(UTEST_ACL_toolchain, AclProfiling_PROF_TYPE_TO_NAMES)
{
    EXPECT_CALL(MockFunctionTest::aclStubInstance(), MsprofRegTypeInfo(_,_,_))
    .WillRepeatedly(Invoke(MsprofRegTypeInfoStubForCnt));
    AclProfilingManager::GetInstance().RegisterProfilingType();
    size_t cnt = (AclProfType::ModelTypeEnd - AclProfType::ModelTypeStart - 1) +
                 (AclProfType::OpTypeEnd - AclProfType::OpTypeStart - 1) +
                 (AclProfType::RtTypeEnd - AclProfType::RtTypeStart - 1) +
                 (AclProfType::OthersTypeEnd - AclProfType::OthersTypeStart - 1);
    EXPECT_EQ(profTypeCnt.size(), cnt);
}
